package com.ruoyi.bzjgl.service.impl;

import com.ruoyi.bzjgl.domain.Bzjtable;
import com.ruoyi.bzjgl.mapper.BankingMapper;
import com.ruoyi.bzjgl.service.BankingService;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class BankingServiceImpl implements BankingService {
    @Autowired
    private BankingMapper bankingMapper;

    //保证金收款
    @Override
    public TableDataInfo collection(Bzjtable bzjtable) {
        bankingMapper.collection(bzjtable);
        TableDataInfo tableDataInfo=new TableDataInfo();
        tableDataInfo.setMsg("Success");
        tableDataInfo.setCode(0);
        return tableDataInfo;
    }

    //查询保证金收款列表
    @Override
    public List<Bzjtable> UnpaidList(Bzjtable bzjtable) {
        return bankingMapper.UnpaidList(bzjtable);
    }

    //查询保证金划拨列表
    @Override
    public List<Bzjtable>  Transfer(Bzjtable bzjtable) {
        List<Bzjtable> list=bankingMapper.Transfer(bzjtable);
        List<Bzjtable> list1=new ArrayList<>();
        int i=0;
        for(Bzjtable bzjtable1 : list){//遍历集合
            BigDecimal sqje;
            BigDecimal  msje;
            BigDecimal  thje;
            BigDecimal  hbje;
            if (bzjtable1.getHbje()!=null){//如果划拨金额存在，则下一位
                i++;
            }else {//否则我自己算划拨金额
                if (bzjtable1.getSqje()!=null){
                    sqje=bzjtable1.getSqje();
                }else {
                    sqje=BigDecimal.ZERO;
                }
                if (bzjtable1.getMsje()!=null){
                    msje=bzjtable1.getMsje();
                }else {
                    msje=BigDecimal.ZERO;
                }
                if (bzjtable1.getThje()!=null){
                    thje=bzjtable1.getThje();
                }else {
                    thje=BigDecimal.ZERO;
                }
                hbje = sqje.subtract(msje).subtract(thje);
                bzjtable1.setHbje(hbje);
                list.set(i,bzjtable1);
                i++;
            }
        }
        return list;
    }

    //划拨保证金
    @Override
    public TableDataInfo updateTransfer(Bzjtable bzjtable) {
        bankingMapper.updateTransfer(bzjtable);
        TableDataInfo tableDataInfo=new TableDataInfo();
        tableDataInfo.setMsg("Success");
        tableDataInfo.setCode(0);
        return tableDataInfo;
    }

    //查询没收执行列表
    @Override
    public List<Bzjtable>  bankSeizurelist(Bzjtable bzjtable) {
        List<Bzjtable> list= bankingMapper.bankSeizurelist(bzjtable);
        return list;
    }

    //查询没收执行列表
    @Override
    public TableDataInfo bankSeizure(Bzjtable bzjtable) {
        bankingMapper.bankSeizure(bzjtable);
        TableDataInfo tableDataInfo=new TableDataInfo();
        tableDataInfo.setMsg("Success");
        tableDataInfo.setCode(0);
        return tableDataInfo;
    }

    //银行退还列表
    @Override
    public List<Bzjtable>  bankRefundlist(Bzjtable bzjtable) {
        return bankingMapper.bankRefundlist(bzjtable);
    }
    //银行退还执行
    @Override
    public TableDataInfo bankRefund(Bzjtable bzjtable) {
        bankingMapper.bankRefund(bzjtable);
        TableDataInfo tableDataInfo=new TableDataInfo();
        tableDataInfo.setMsg("Success");
        tableDataInfo.setCode(0);
        return tableDataInfo;    }
}
